##############
## American Identity, Status Threat, and Backlash - Study 2, Public
##############

##############
## Load data
##############
rm(list=ls())
S2_D1 <- read.csv("Study 2 raw.csv", header = TRUE)
head(S2_D1)
nrow(S2_D1)
ncol(S2_D1)


##############
## Exclude participants who failed the attention check
##############
variable.names(S2_D1)
table(S2_D1$Att_Check2)
nrow(S2_D1)

## remove based on main attention check
S2_D2 <- S2_D1[which((S2_D1$Att_Check2) %in% c("meow","Meow","meow meow","meow =^.^=","meow!","meow or purr","Mhew :)","Mew","purr","No noise cat made","meows","meow!","Meow.","no","mew or meow, depending on how silly the cat is.",
                                                    "Meow man","pur","MEOW","meow or miaow","meeow","meeowww","purrrrrrr","Meow meow","Meow!","moi","meows","meyow","none","MEOWW","Miya miya","meowwww","MEOW!","meow purrrrrrrrr",
                                                    "meow!","mew","mewow","miau"," Meow!","this cat looks irritated, so it would be a growly kind of meow. Give him a treat.",
                                                    "PURR", "purrrrr", "Purr","Mrrp?  Mrrrrrow.  mrrrrAAAAAA!","miow","miaow", " Miao or meow","Meow  Prrr Prrr","meow (or purrrrrr...) ","meow (or nya in japanese) ", "meo", "mea", "Meows",
                                                    "MEOOOOOW", "Bark", "meow (or nya in japanese)","meow (or purrrrrr...)","Either a purr or a meow", "Meaw", "meow, hiss!","meow, meow, meeeeooww, mew, meow","meow and purr", "Meow Hiss",
                                                    "meo","meoww","myaw","meeyow","Miao or meow","Meawww","meowwwwww","Meoww","meow/purr", "cat", "meow", "MEOW MEOW", "Meow Meow", " meow", "meoow",
                                                    "MEOW MEOW", "Meow Meow","purr purr meow hissss","meow ","Mew, meow...","MEOW, purrrrrr!","	meooow!","meooow!","Meow","Meow, hiss","myau","Purr! :)","Meowww","Meow ","MEOOOWW","Meowwwew","Meow! ","Meowwww","Meow meow! =^.^=","Meow ")), ]
nrow(S2_D2)

## check those who failed
S2_D0 <- S2_D1[-which((S2_D1$Att_Check2) %in% c("meow","Meow","meow meow","meow =^.^=","meow!","meow or purr","Mhew :)","Mew","purr","No noise cat made","meows","meow!","Meow.","no","mew or meow, depending on how silly the cat is.",
                                                "Meow man","pur","MEOW","meow or miaow","meeow","meeowww","purrrrrrr","Meow meow","Meow!","moi","meows","meyow","none","MEOWW","Miya miya","meowwww","MEOW!","meow purrrrrrrrr",
                                                "meow!","mew","mewow","miau"," Meow!","this cat looks irritated, so it would be a growly kind of meow. Give him a treat.",
                                                "PURR", "purrrrr", "Purr","Mrrp?  Mrrrrrow.  mrrrrAAAAAA!","miow","miaow", " Miao or meow","Meow  Prrr Prrr","meow (or purrrrrr...) ","meow (or nya in japanese) ", "meo", "mea", "Meows",
                                                "MEOOOOOW", "Bark", "meow (or nya in japanese)","meow (or purrrrrr...)","Either a purr or a meow", "Meaw", "meow, hiss!","meow, meow, meeeeooww, mew, meow","meow and purr", "Meow Hiss",
                                                "meo","meoww","myaw","meeyow","Miao or meow","Meawww","meowwwwww","Meoww","meow/purr", "cat", "meow", "MEOW MEOW", "Meow Meow", " meow", "meoow",
                                                "MEOW MEOW", "Meow Meow","purr purr meow hissss","meow ","Mew, meow...","MEOW, purrrrrr!","	meooow!","meooow!","Meow","Meow, hiss","myau","Purr! :)","Meowww","Meow ","MEOOOWW","Meowwwew","Meow! ","Meowwww","Meow meow! =^.^=","Meow ")), ]
nrow(S2_D0)
#view(S2_D0$Att_Check2)
library(rstatix)
chisq_test(S2_D0$Att_Check2, S2_D0$Condition) ## inattentiveness does not vary by condition

## remove based on second attention check
table(S2_D2$White_ID_6)
S2_D3 <- subset(S2_D2, S2_D2$White_ID_6=="3") 
nrow(S2_D3)
chisq_test(S2_D2$White_ID_6, S2_D2$Condition) ## inattentiveness does not vary by condition

## Exclude all non-whites
table(S2_D3$Ethnicity)
S2_D3 <- subset(S2_D3, S2_D3$Ethnicity==1) 
nrow(S2_D3)

##############
## Demographic summary + balance tests
##############
variable.names(S2_D3)

S2_D3$Condition [S2_D3$Condition == 1] <- "Control"
S2_D3$Condition [S2_D3$Condition == 2] <- "Common Identity"

is.factor(S2_D3$Condition)

## Demographics
mean(S2_D3$Age, na.rm = TRUE)
sd(S2_D3$Age, na.rm = TRUE)
round(table(S2_D3$Ideology)/nrow(S2_D3)*100,2) ## percentage liberal
round(table(S2_D3$Gender)/nrow(S2_D3)*100,2) ## percentage gender

## Balance tests
nrow(S2_D3)
table(S2_D3$Condition)
chisq.test(table(S2_D3$Condition, S2_D3$Age))
chisq.test(table(S2_D3$Condition, S2_D3$Gender))
chisq.test(table(S2_D3$Condition, S2_D3$Education))
chisq.test(table(S2_D3$Condition, S2_D3$Ideology))

##############
## Recode reverse-coded items and rename variables
##############
## recode second status threat item
library(car)
S2_D3$Status_Threat_2 = car::recode(S2_D3$Status_Threat_2, "1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else = NA")
S2_D3$Status_Threat_4 = car::recode(S2_D3$Status_Threat_4, "1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else = NA")

S2_D3$American_ID_1 = car::recode(S2_D3$American_ID_1, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S2_D3$American_ID_2 = car::recode(S2_D3$American_ID_2, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S2_D3$American_ID_3 = car::recode(S2_D3$American_ID_3, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S2_D3$American_ID_4 = car::recode(S2_D3$American_ID_4, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")

S2_D3$Americanness_1 = car::recode(S2_D3$Americanness_1, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S2_D3$Americanness_2 = car::recode(S2_D3$Americanness_2, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S2_D3$Americanness_3 = car::recode(S2_D3$Americanness_3, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S2_D3$Americanness_4 = car::recode(S2_D3$Americanness_4, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S2_D3$Americanness_5 = car::recode(S2_D3$Americanness_5, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S2_D3$Americanness_6 = car::recode(S2_D3$Americanness_6, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")

##############
## Factorial structure outgroup thermometers
##############
S2_D3_thermometers <- S2_D3[,c(31:35)]
head(S2_D3_thermometers)

## Visualize with scree plot
library(ggplot2)
library(psych)
fafitfree <- fa(S2_D3_thermometers,nfactors = 1, rotate = "promax", fm = "ml")
n_factors <- length(fafitfree$e.values)
scree     <- data.frame(
  Factor_n =  as.factor(1:n_factors), 
  Eigenvalue = fafitfree$e.values)
ggplot(scree, aes(x = Factor_n, y = Eigenvalue, group = 1)) + 
  geom_point() + geom_line() +
  xlab("Number of factors") +
  ylab("Initial eigenvalue") +
  labs( title = "Scree Plot", 
        subtitle = "(Based on the unreduced correlation matrix)")

##############
## Factorial structure outgroup Americanness
##############
S2_D3_americanness <- S2_D3[,c(39:41)]
head(S2_D3_americanness)

## Visualize with scree plot
library(ggplot2)
fafitfree <- fa(S2_D3_americanness,nfactors = 1, rotate = "promax", fm = "ml")
n_factors <- length(fafitfree$e.values)
scree     <- data.frame(
  Factor_n =  as.factor(1:n_factors), 
  Eigenvalue = fafitfree$e.values)
ggplot(scree, aes(x = Factor_n, y = Eigenvalue, group = 1)) + 
  geom_point() + geom_line() +
  xlab("Number of factors") +
  ylab("Initial eigenvalue") +
  labs( title = "Scree Plot", 
        subtitle = "(Based on the unreduced correlation matrix)")

##############
## Reliabilities
##############
colnames(S2_D3)
which( colnames(S2_D3)=="Americanness_6" )

psych::alpha(select(S2_D3, 19:23)) ## Status threat
psych::alpha(select(S2_D3, 24:27)) ## American ID
psych::alpha(select(S2_D3, 45:49)) ## White ID
psych::alpha(select(S2_D3, 31:35)) ## Outgroup thermometers
psych::alpha(select(S2_D3, 39:41)) ## Perceived Americanness


##############
## Mean Scales
##############
S2_D3$mean_Status_Threat <- (S2_D3$Status_Threat_1 + S2_D3$Status_Threat_2 + S2_D3$Status_Threat_3 + S2_D3$Status_Threat_4 + S2_D3$Status_Threat_5)/5
S2_D3$mean_American_Identity <- (S2_D3$American_ID_1 + S2_D3$American_ID_2 + S2_D3$American_ID_3 + S2_D3$American_ID_4)/4
S2_D3$mean_White_Identity <- (S2_D3$White_ID_1 + S2_D3$White_ID_2 + S2_D3$White_ID_3 + S2_D3$White_ID_4 + S2_D3$White_ID_5)/5
S2_D3$mean_Outgroup_Warmth <- (S2_D3$Thermometers_6 + S2_D3$Thermometers_7 + S2_D3$Thermometers_8 + S2_D3$Thermometers_9 + S2_D3$Thermometers_10)/5
S2_D3$mean_Perceived_Americanness <- (S2_D3$Americanness_4 + S2_D3$Americanness_5 + S2_D3$Americanness_6)/3


##############
## Rescaling
##############
S2_D3$mean_Status_Threat_scaled <- (S2_D3$mean_Status_Threat - min(S2_D3$mean_Status_Threat, na.rm = TRUE)) / (max(S2_D3$mean_Status_Threat, na.rm = TRUE) - min(S2_D3$mean_Status_Threat, na.rm = TRUE))
S2_D3$mean_American_Identity_scaled <- (S2_D3$mean_American_Identity - min(S2_D3$mean_American_Identity, na.rm = TRUE)) / (max(S2_D3$mean_American_Identity, na.rm = TRUE) - min(S2_D3$mean_American_Identity, na.rm = TRUE))
S2_D3$mean_White_Identity_scaled <- (S2_D3$mean_White_Identity - min(S2_D3$mean_White_Identity, na.rm = TRUE)) / (max(S2_D3$mean_White_Identity, na.rm = TRUE) - min(S2_D3$mean_White_Identity, na.rm = TRUE))
S2_D3$mean_Outgroup_Warmth_scaled <- (S2_D3$mean_Outgroup_Warmth - min(S2_D3$mean_Outgroup_Warmth, na.rm = TRUE)) / (max(S2_D3$mean_Outgroup_Warmth, na.rm = TRUE) - min(S2_D3$mean_Outgroup_Warmth, na.rm = TRUE))
S2_D3$IOS_scaled <- (S2_D3$IOS - min(S2_D3$IOS, na.rm = TRUE)) / (max(S2_D3$IOS, na.rm = TRUE) - min(S2_D3$IOS, na.rm = TRUE))
S2_D3$mean_Perceived_Americanness_scaled <- (S2_D3$mean_Perceived_Americanness - min(S2_D3$mean_Perceived_Americanness, na.rm = TRUE)) / (max(S2_D3$mean_Perceived_Americanness, na.rm = TRUE) - min(S2_D3$mean_Perceived_Americanness, na.rm = TRUE))
S2_D3$Dems_scaled <- (S2_D3$Thermometers_3 - min(S2_D3$Thermometers_3, na.rm = TRUE)) / (max(S2_D3$Thermometers_3, na.rm = TRUE) - min(S2_D3$Thermometers_3, na.rm = TRUE))
S2_D3$Reps_scaled <- (S2_D3$Thermometers_4 - min(S2_D3$Thermometers_4, na.rm = TRUE)) / (max(S2_D3$Thermometers_4, na.rm = TRUE) - min(S2_D3$Thermometers_4, na.rm = TRUE))

S2_D3$Blacks_scaled <- (S2_D3$Thermometers_6 - min(S2_D3$Thermometers_6, na.rm = TRUE)) / (max(S2_D3$Thermometers_6, na.rm = TRUE) - min(S2_D3$Thermometers_6, na.rm = TRUE))
S2_D3$Asians_scaled <- (S2_D3$Thermometers_7 - min(S2_D3$Thermometers_7, na.rm = TRUE)) / (max(S2_D3$Thermometers_7, na.rm = TRUE) - min(S2_D3$Thermometers_7, na.rm = TRUE))
S2_D3$Hispanics_scaled <- (S2_D3$Thermometers_8 - min(S2_D3$Thermometers_8, na.rm = TRUE)) / (max(S2_D3$Thermometers_8, na.rm = TRUE) - min(S2_D3$Thermometers_8, na.rm = TRUE))
S2_D3$Illegal_scaled <- (S2_D3$Thermometers_9 - min(S2_D3$Thermometers_9, na.rm = TRUE)) / (max(S2_D3$Thermometers_9, na.rm = TRUE) - min(S2_D3$Thermometers_9, na.rm = TRUE))
S2_D3$Legal_scaled <- (S2_D3$Thermometers_10 - min(S2_D3$Thermometers_10, na.rm = TRUE)) / (max(S2_D3$Thermometers_10, na.rm = TRUE) - min(S2_D3$Thermometers_10, na.rm = TRUE))
S2_D3$Americanness_Blacks_scaled <- (S2_D3$Americanness_4 - min(S2_D3$Americanness_4, na.rm = TRUE)) / (max(S2_D3$Americanness_4, na.rm = TRUE) - min(S2_D3$Americanness_4, na.rm = TRUE))
S2_D3$Americanness_Asians_scaled <- (S2_D3$Americanness_5 - min(S2_D3$Americanness_5, na.rm = TRUE)) / (max(S2_D3$Americanness_5, na.rm = TRUE) - min(S2_D3$Americanness_5, na.rm = TRUE))
S2_D3$Americanness_Hispanics_scaled <- (S2_D3$Americanness_6 - min(S2_D3$Americanness_6, na.rm = TRUE)) / (max(S2_D3$Americanness_6, na.rm = TRUE) - min(S2_D3$Americanness_6, na.rm = TRUE))
S2_D3$Americanness_Whites_scaled <- (S2_D3$Americanness_3 - min(S2_D3$Americanness_3, na.rm = TRUE)) / (max(S2_D3$Americanness_3, na.rm = TRUE) - min(S2_D3$Americanness_3, na.rm = TRUE))
S2_D3$Americanness_Dems_scaled <- (S2_D3$Americanness_1 - min(S2_D3$Americanness_1, na.rm = TRUE)) / (max(S2_D3$Americanness_1, na.rm = TRUE) - min(S2_D3$Americanness_1, na.rm = TRUE))
S2_D3$Americanness_Reps_scaled <- (S2_D3$Americanness_2 - min(S2_D3$Americanness_2, na.rm = TRUE)) / (max(S2_D3$Americanness_2, na.rm = TRUE) - min(S2_D3$Americanness_2, na.rm = TRUE))

S2_D3$Ideology_scaled <- (S2_D3$Ideology - min(S2_D3$Ideology, na.rm = TRUE)) / (max(S2_D3$Ideology, na.rm = TRUE) - min(S2_D3$Ideology, na.rm = TRUE))


##############
## Descriptives
##############
library(dplyr)
table(S2_D3$Condition)
S2_D3$Condition <- factor(S2_D3$Condition, levels = c("Control", "Common Identity"))
S2_D3$Condition_num <- as.numeric(as.factor(S2_D3$Condition))
table(S2_D3$Condition_num)

S2_t1 <- t(round(S2_D3 %>%
                   group_by(Condition_num) %>%
                   summarise_at(vars(c(mean_Status_Threat_scaled, mean_American_Identity_scaled, mean_White_Identity_scaled,
                                       mean_Outgroup_Warmth_scaled, IOS_scaled,mean_Perceived_Americanness_scaled,
                                       Dems_scaled,Reps_scaled,
                                       Blacks_scaled,Asians_scaled,Hispanics_scaled,Illegal_scaled,Legal_scaled,
                                       Americanness_Blacks_scaled,Americanness_Asians_scaled,Americanness_Hispanics_scaled,
                                       Americanness_Whites_scaled,Americanness_Dems_scaled,Americanness_Reps_scaled)), list(mean = mean, sd = sd), na.rm = TRUE),2))
write.table(S2_t1, file = "S2_t1.txt", sep = ",", quote = FALSE, row.names = F)


##############
## Simple mean differences (descriptive, not used for hypothesis testing)
##############
## Status threat
S2_aov1 <- aov(mean_Status_Threat_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov1)
S2_reg1 <- lm(mean_Status_Threat_scaled ~ factor(Condition), data = S2_D3)
summary(S2_reg1)

library(effectsize)
cohens_f(S2_reg1, partial = FALSE)

## American identity
S2_aov2 <- aov(mean_American_Identity_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov2)
S2_reg2 <- lm(mean_American_Identity_scaled ~ factor(Condition), data = S2_D3)
summary(S2_reg2)
cohens_f(S2_reg2, partial = FALSE)

## White identity
S2_aov3 <- aov(mean_White_Identity_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov3)
S2_reg3 <- lm(mean_White_Identity_scaled ~ factor(Condition), data = S2_D3)
summary(S2_reg3)

## Outgroup warmth
S2_aov4 <- aov(mean_Outgroup_Warmth_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov4)
S2_reg4 <- lm(mean_Outgroup_Warmth_scaled ~ factor(Condition), data = S2_D3)
summary(S2_reg4)

## Inclusiveness
S2_aov5 <- aov(IOS_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov5)
S2_reg5 <- lm(IOS_scaled ~ factor(Condition), data = S2_D3)
summary(S2_reg5)

## Americanness
S2_aov6 <- aov(mean_Perceived_Americanness_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov6)
S2_reg6 <- lm(mean_Perceived_Americanness_scaled ~ factor(Condition), data = S2_D3)
summary(S2_reg6)

## Democrat warmth
S2_aov7 <- aov(Dems_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov7)
S2_reg7 <- lm(Dems_scaled ~ factor(Condition), data = S2_D3)
summary(S2_reg7)

## Republican warmth
S2_aov8 <- aov(Reps_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov8)
S2_reg8 <- lm(Reps_scaled ~ factor(Condition), data = S2_D3)
summary(S2_reg8)

## Separate outgroups: thermometers
S2_aov9a <- aov(Blacks_scaled ~ factor(Condition), data = S2_D3)
S2_aov9b <- aov(Asians_scaled ~ factor(Condition), data = S2_D3)
S2_aov9c <- aov(Hispanics_scaled ~ factor(Condition), data = S2_D3)
S2_aov9d <- aov(Illegal_scaled ~ factor(Condition), data = S2_D3)
S2_aov9e <- aov(Legal_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov9a)
summary(S2_aov9b)
summary(S2_aov9c)
summary(S2_aov9d)
summary(S2_aov9e)

## Separate outgroups: Americanness
S2_aov10a <- aov(Americanness_Blacks_scaled ~ factor(Condition), data = S2_D3)
S2_aov10b <- aov(Americanness_Asians_scaled ~ factor(Condition), data = S2_D3)
S2_aov10c <- aov(Americanness_Hispanics_scaled ~ factor(Condition), data = S2_D3)
S2_aov10d <- aov(Americanness_Whites_scaled ~ factor(Condition), data = S2_D3)
summary(S2_aov10a)
summary(S2_aov10b)
summary(S2_aov10c)
summary(S2_aov10d)



##############
## Moderating ideology
##############
S2_aov1_ideo <- aov(mean_Status_Threat_scaled ~ factor(Condition)*Ideology_scaled, data = S2_D3)
summary(S2_aov1_ideo)
S2_reg1_ideo <- lm(mean_Status_Threat_scaled ~ factor(Condition)*Ideology_scaled, data = S2_D3)
summary(S2_reg1_ideo)

S2_aov2_ideo <- aov(mean_American_Identity_scaled ~ factor(Condition)*Ideology_scaled, data = S2_D3)
summary(S2_aov2_ideo)
S2_reg2_ideo <- lm(mean_American_Identity_scaled ~ factor(Condition)*Ideology_scaled, data = S2_D3)
summary(S2_reg2_ideo)

S2_aov3_ideo <- aov(mean_Status_Threat_scaled ~ mean_American_Identity_scaled*Ideology_scaled, data = S2_D3)
summary(S2_aov3_ideo)
S2_reg3_ideo <- lm(mean_Status_Threat_scaled ~ mean_American_Identity_scaled*Ideology_scaled, data = S2_D3)
summary(S2_reg3_ideo)

S2_reg4_ideo <- lm(mean_White_Identity_scaled ~ factor(Condition)*Ideology_scaled, data = S2_D3)
summary(S2_reg4_ideo)

##############
## Mediation through status threat
##############
library(lavaan)

## Dummy-code conditions
table(S2_D3$Condition)
S2_D3$Condition_CIIM <- ifelse (S2_D3$Condition =="Common Identity", 1, 0)

## Comparison CIIM vs. control
## insert DV as needed
S2_D3_simple_mediation <- '
## Direct effect condition on outcomes (path c) 
Reps_scaled ~ c1*Condition_CIIM

## Indirect effect 1: condition on reported American identity (path a)
mean_Status_Threat_scaled ~ a1*Condition_CIIM

## Indirect effect 2: reported American identity on status threat + controls (path b)
Reps_scaled ~ b1*mean_Status_Threat_scaled

## direct effect
direct_CIIM := c1

## indirect effect (a*b): Sobel test (Delta method)
indirect_CIIM := a1*b1

## total effect
total_CIIM := c1 + (a1*b1)
'

## comparing CIIM vs. control
S2_D3_simple_mediation_Outgroup_fit <- sem(S2_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S2_D3)
S2_D3_simple_mediation_Inclusiveness_fit <- sem(S2_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S2_D3)
S2_D3_simple_mediation_Americanness_fit <- sem(S2_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S2_D3)
S2_D3_simple_mediation_Democrats_fit <- sem(S2_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S2_D3)
S2_D3_simple_mediation_Republicans_fit <- sem(S2_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S2_D3)
summary(S2_D3_simple_mediation_Outgroup_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S2_D3_simple_mediation_Inclusiveness_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S2_D3_simple_mediation_Americanness_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S2_D3_simple_mediation_Democrats_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S2_D3_simple_mediation_Republicans_fit, fit.measures = TRUE, rsquare = TRUE)


##############
## Exploratory: Effect on affective polarization
##############
## Compute AP-score
S2_D3$AP_score <- abs((S2_D3$Thermometers_3 - S2_D3$Thermometers_4))
head(S2_D3[1:6,c("Thermometers_3","Thermometers_4","AP_score")])

## Run regressions
S2_aovAP <- aov(AP_score ~ factor(Condition), data = S2_D3)
summary(S2_aovAP)
S2_regAP <- lm(AP_score ~ factor(Condition), data = S2_D3)
summary(S2_regAP)
cohens_f(S2_regAP, partial = FALSE)


##############
## End of the syntax.



